import { defineStore } from "pinia";
import { encryptedSerializer } from "@/utils/jiami";

// 使用接口定义 state 的类型
interface stateType {
  locale: string;
  loadDing: boolean;
  nowMenu:number;
}

// 定义一个名为 "counter" 的 Pinia store
export const useSystemStore = defineStore("system", {
  // 初始化 state
  state: (): stateType => ({
    locale: "zh",
    loadDing: false,
    nowMenu:1,
  }),

  // 定义 actions 用于修改 state
  actions: {
    // 增加 counter 的值
    setLocale(str: string): void {
      this.locale = str;
    },
    setLoading(bool: boolean): void {
      this.loadDing = bool;
    },
    setNowMenu(num:number):void{
      this.nowMenu = num;
    }
  },
  persist: {
    serializer: encryptedSerializer,
    enabled: true,
    storage: localStorage,
  },
});
// 定义 StoreType 类型，表示 useStore 的返回类型
export type StoreType = ReturnType<typeof useSystemStore>;
